﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x020001A1 RID: 417
	public class HandPoser : Poser
	{
		// Token: 0x06000896 RID: 2198 RVA: 0x0002F090 File Offset: 0x0002D490
		public override void AutoMapping()
		{
			if (this.poseRoot == null)
			{
				this.poseChildren = new Transform[0];
			}
			else
			{
				this.poseChildren = this.poseRoot.GetComponentsInChildren<Transform>();
			}
			this._poseRoot = this.poseRoot;
		}

		// Token: 0x06000897 RID: 2199 RVA: 0x0002F0DC File Offset: 0x0002D4DC
		protected override void InitiatePoser()
		{
			this.children = base.GetComponentsInChildren<Transform>();
			this.StoreDefaultState();
		}

		// Token: 0x06000898 RID: 2200 RVA: 0x0002F0F0 File Offset: 0x0002D4F0
		protected override void FixPoserTransforms()
		{
			for (int i = 0; i < this.children.Length; i++)
			{
				this.children[i].localPosition = this.defaultLocalPositions[i];
				this.children[i].localRotation = this.defaultLocalRotations[i];
			}
		}

		// Token: 0x06000899 RID: 2201 RVA: 0x0002F154 File Offset: 0x0002D554
		protected override void UpdatePoser()
		{
			if (this.weight <= 0f)
			{
				return;
			}
			if (this.localPositionWeight <= 0f && this.localRotationWeight <= 0f)
			{
				return;
			}
			if (this._poseRoot != this.poseRoot)
			{
				this.AutoMapping();
			}
			if (this.poseRoot == null)
			{
				return;
			}
			if (this.children.Length != this.poseChildren.Length)
			{
				Warning.Log("Number of children does not match with the pose", base.transform, false);
				return;
			}
			float t = this.localRotationWeight * this.weight;
			float t2 = this.localPositionWeight * this.weight;
			for (int i = 0; i < this.children.Length; i++)
			{
				if (this.children[i] != base.transform)
				{
					this.children[i].localRotation = Quaternion.Lerp(this.children[i].localRotation, this.poseChildren[i].localRotation, t);
					this.children[i].localPosition = Vector3.Lerp(this.children[i].localPosition, this.poseChildren[i].localPosition, t2);
				}
			}
		}

		// Token: 0x0600089A RID: 2202 RVA: 0x0002F290 File Offset: 0x0002D690
		private void StoreDefaultState()
		{
			this.defaultLocalPositions = new Vector3[this.children.Length];
			this.defaultLocalRotations = new Quaternion[this.children.Length];
			for (int i = 0; i < this.children.Length; i++)
			{
				this.defaultLocalPositions[i] = this.children[i].localPosition;
				this.defaultLocalRotations[i] = this.children[i].localRotation;
			}
		}

		// Token: 0x04000563 RID: 1379
		private Transform _poseRoot;

		// Token: 0x04000564 RID: 1380
		private Transform[] children;

		// Token: 0x04000565 RID: 1381
		private Transform[] poseChildren;

		// Token: 0x04000566 RID: 1382
		private Vector3[] defaultLocalPositions;

		// Token: 0x04000567 RID: 1383
		private Quaternion[] defaultLocalRotations;
	}
}
